package com.wanbangee.marksystem.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wanbangee.marksystem.entities.UClass;
import com.wanbangee.marksystem.entities.UGrade;
import com.wanbangee.marksystem.entities.USchool;
import com.wanbangee.marksystem.service.UClassService;

@RestController
@RequestMapping("classManage")
public class UClassController {
	
	@Autowired
	private UClassService uClassService;
	
	@PutMapping("updateClass")
	public Map<String, Object> updateClass(UClass uClass) {
		Map<String, Object> map = new HashMap<String, Object>();
		int updateClassState = this.uClassService.updateClass(uClass);
		if(updateClassState > 0) {
			map.put("code", 1001);
			map.put("message", "接口成功");
		}
		return map;
	}
	
	@GetMapping("selectSchool")
	public Map<String, Object> selectSchool() {
		Map<String, Object> map = new HashMap<String, Object>();
		List<USchool> lists = this.uClassService.selectSchool();
		map.put("code", 1001);
		map.put("message", "接口成功");
		map.put("lists", lists);
		return map;
	}
	
	@GetMapping("selectGradeBySchId")
	public Map<String, Object> selectGradeBySchId(int schId) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<UGrade> lists = this.uClassService.selectGradeBySchId(schId);
		map.put("code", 1001);
		map.put("message", "接口成功");
		map.put("lists", lists);
		return map;
	}
	
	@GetMapping("selectClassInfoBySchIdAndGraId")
	public Map<String, Object> selectClassInfoBySchIdAndGraId(int schId, int graId) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<UClass> lists = this.uClassService.selectClassInfoBySchIdAndGraId(schId, graId);
		map.put("code", 1001);
		map.put("message", "接口成功");
		map.put("lists", lists);
		return map;
	}
	
	@PostMapping("insertClass")
	public Map<String, Object> insertClass(UClass uClass) {
		Map<String, Object> map = new HashMap<String, Object>();
		int insertClassState = this.uClassService.insertClass(uClass);
		if(insertClassState > 0) {
			map.put("code", 1001);
			map.put("message", "接口成功");
		}
		return map;
	}
	
	@GetMapping("selectClassByclaId")
	public Map<String, Object> selectClassByclaId(int claId) {
		Map<String, Object> map = new HashMap<String, Object>();
		UClass uClass = this.uClassService.selectClassByclaId(claId);
		map.put("code", 1001);
		map.put("message", "接口成功");
		map.put("uClass", uClass);
		return map;
	}
	
	@PutMapping("deleteClass")
	public Map<String, Object> deleteClass(int claId) {
		Map<String, Object> map = new HashMap<String, Object>();
		int deleteClass = this.uClassService.deleteClass(claId);
		if(deleteClass > 0) {
			map.put("code", 1001);
			map.put("message", "接口成功");
		}
		return map;
	}
	
	@PutMapping("updateClaState")
	public Map<String, Object> updateClaState(int claId, int claState) {
		Map<String, Object> map = new HashMap<String, Object>();
		int updateClaState = this.uClassService.updateClaState(claId, claState);
		if(updateClaState > 0) {
			map.put("code", 1001);
			map.put("message", "接口成功");
		}
		return map;
	}

	@PutMapping("updateClassGrade")
	public Map<String, Object> updateClassGrade(int claId, int graId, String graNm) {
		Map<String, Object> map = new HashMap<String, Object>();
		int updateClassGradeState = this.uClassService.updateClassGrade(claId, graId, graNm);
		if(updateClassGradeState > 0) {
			map.put("code", 1001);
			map.put("message", "接口成功");
		}
		return map;
	}

}